package com.hqu.jim.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = {"/login"})
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String username = (String)req.getParameter("username");
        String password = (String)req.getParameter("password");
        if(password.equals("12345")){
            req.getSession().setAttribute("username",username);
            resp.sendRedirect("/index.jsp");
        }
        else {
            req.setAttribute("msg","密码错误！");
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }
    }
}
